namespace Sustainalytics.Entities
{
    using System;
    using System.Collections.Generic;
    using System.Linq;

    public class ManualSystemPortfolio : SystemPortfolio
    {
        public ManualSystemPortfolio(string name, Guid accountId, Guid userId, string userName, string userFullName)
            : base(Guid.NewGuid(), name, new[] { accountId })
        {
            this.AddedByFullName = userFullName;
            this.AddedByUserId = userId;
            this.AddedByUserName = userName;
            this.IsReadonly = false;
            this.DateModified = DateTime.Today;
            this.DataCreated = DateTime.Today;
            this.SharingStatus = PortfolioSharingStatus.Private;
        }

        internal ManualSystemPortfolio()
        {
        }


        public void UpdateManualSystemPortfolioAssociatedUniverses(IEnumerable<Portfolio> associatedPortfolios)
        {
            var filteredAssociatedUniverses =
             associatedPortfolios.Where(x => x.AccountIds.Contains(x.AccountIds.First())).ToList();
            this.RelatedUniverses = filteredAssociatedUniverses.Select(x => new RelatedUniverse(x.Id, x.Name)).ToList();
            this.DateModified = DateTime.Today;
            this.CompanyCount = filteredAssociatedUniverses.Sum(x => x.CompanyCount);
        }
    }
}